package com.zhouyer.study.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 验证码生产器配置类
 *
 * @author zhouyao
 * @version 1.0
 * @date 2021/12/6 9:31 下午
 */
@Configuration
public class KaptchaConfig {
    @Bean
    public Config config() {
        Properties properties = new Properties();
        properties.setProperty("kaptcha.border", "no");
        properties.setProperty("kaptcha.textproducer.font.color", "black");
        properties.setProperty("kaptcha.textproducer.char.space", "4");
        properties.setProperty("kaptcha.textproducer.char.length", "6");
        properties.setProperty("kaptcha.textproducer.char.string", "123456789");
        Config config = new Config(properties);
        return config;
    }

    @Bean
    public Producer producer(Config config) {
        DefaultKaptcha producer = new DefaultKaptcha();
        producer.setConfig(config);
        return producer;
    }

}
